using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class UICraftList : MonoBehaviour,IPointerDownHandler
{
    [SerializeField] private Transform craftSlotParent;
    [SerializeField] private GameObject craftSlotPrefab;
    [SerializeField] private List<ItemData_Equipment> craftEquipment;

    void Start()
    {
        transform.parent.GetChild(0).GetComponent<UICraftList>().SetUpCraftList();
        SetUpDefaultCraftWindow();
    }
    public void SetUpCraftList() 
    {
        for (int i = 0; i < craftSlotParent.childCount; i++)
        {
            Destroy(craftSlotParent.GetChild(i).gameObject);
        }
        for(int i=0;i<craftEquipment.Count;i++)
        {
            GameObject newSlot = Instantiate(craftSlotPrefab, craftSlotParent);
            newSlot.GetComponent<UI_CraftSlot>().SetUpCraftSlot(craftEquipment[i]);
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        SetUpCraftList();
    }
    public void SetUpDefaultCraftWindow()
    {
        GetComponentInParent<UI>().craftwindow.SetUpCraftWindow(craftEquipment[0]);
    }
}
